//
//  YCBasicViewController.swift
//  swift微博
//
//  Created by 姚伟聪 on 15/12/16.
//  Copyright © 2015年 姚伟聪. All rights reserved.
//

import UIKit

class YCBasicViewController: UITableViewController,YCBaseViewDelegate {

    var isload:Bool = YCUserAccount.isUseLogin
    
    override func loadView() {
        //这是在子类会自动调用这个方法，所以才会有这种选择的效果
         isload ? super.loadView() : stepView()
       
        
    }
    override func viewDidLoad() {
        
        super.viewDidLoad()

    }
    private func setNavBarItems(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registe")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
        
    }
    //MARK: - 导航栏按钮点击
    func registe(){
        self.baseViewRegisteClick()
    
    }
    func login(){
    
        self.baseViewLoginClick()
    }
    //MARK: - 加载不同页面
    func stepView(){
        
        view = vistoryView
          setNavBarItems()
        vistoryView.delegate = self
        
        if self is YCHomeViewController{
        
            vistoryView.startAnimation()
            //这里接受通知
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackGround", name: UIApplicationDidEnterBackgroundNotification, object: nil)
              NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecameActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
            
        }else if self is YCDiscoveryViewController{
        
            vistoryView.changeVisiterView("visitordiscover_image_message", textString: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            
        }else if self is YCMessageViewController{
        vistoryView.changeVisiterView("visitordiscover_image_message", textString: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        
        }else if self is YCProfileViewController{
        vistoryView.changeVisiterView("visitordiscover_image_profile", textString: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        
        
    }
    func didEnterBackGround(){
       
        vistoryView.pauseAnimation()
    }
    func didBecameActive(){
    
        vistoryView.resumeAnimation()
    }
    
    //MARK: - 访客视图代理方法
    func baseViewLoginClick() {
        
        let oAuthController = YCoAuthViewController()
        
        let nav = UINavigationController(rootViewController: oAuthController)
        
        presentViewController(nav, animated: true, completion: nil)
        
        
        
    }
    func baseViewRegisteClick() {
        print("registe")
    }
    

    
    ///MARK:- 懒加载
    lazy var vistoryView:YCBaseView = YCBaseView()
   

    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source






}
